{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "11836a48-24a1-4ee1-93a3-06d4fa2819a6",
   "metadata": {},
   "outputs": [],
   "source": [
    " # 导入turtle模块的所有功能\n",
    "from turtle import *\n",
    "\n",
    "# 设置填充颜色为红色\n",
    "fillcolor('red')\n",
    "\n",
    "# 开始填充颜色\n",
    "begin_fill()\n",
    "\n",
    "# 无限循环\n",
    "while True:   \n",
    "    forward(200) # 向前移动200个单位\n",
    "    right(144) # 向右转动144度\n",
    "\n",
    "    # 检查海龟的位置是否接近原点（即pos()的绝对值小于1）\n",
    "    if abs(pos())<1:\n",
    "\n",
    "        break # 如果接近原点，则退出循环\n",
    "\n",
    "# 结束填充颜色\n",
    "end_fill()\n",
    "# 结束绘图，保持窗口打开直到用户关闭\n",
    "done()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "b908d4e9-013c-4330-9afe-4a69f679dc7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "运算结果为：4037913\n"
     ]
    }
   ],
   "source": [
    "# 初始化变量sum和tmp，sum用于存储最终结果，tmp用于中间计算\n",
    "sum,tmp=0,1\n",
    "\n",
    "# 使用for循环，循环变量i从1遍历到10（包含1，不包含11）\n",
    "for i in range(1,11):\n",
    "    # tmp变量乘以当前的循环变量i，这里tmp实际上是在计算i的阶乘\n",
    "    tmp*=i\n",
    "     # 将更新后的tmp值（即当前的阶乘值）加到sum变量上\n",
    "    sum+=tmp\n",
    "    \n",
    "# 打印最终的计算结果\n",
    "print('运算结果为：{}'.format(sum))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e50c79f9-7a40-44ae-b6ae-3e3363751cbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcdef'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#函数\n",
    "def add(i,j):#def 声明函数的关键字，add 函数名称；i，j：参数\n",
    "    k=i+j\n",
    "    return k\n",
    "\n",
    "add(2,5)\n",
    "add(2.7,4.5)\n",
    "add('abc','def')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a103d8fc-9f66-48f7-94d6-554f7b53f181",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "7.2\n",
      "abcdef\n"
     ]
    }
   ],
   "source": [
    "def add(i, j):  # def 声明函数的关键字，add 函数名称；i，j：参数\n",
    "    k = i + j\n",
    "    return k\n",
    "\n",
    "# 调用函数\n",
    "print(add(2, 5))     # 输出整数相加的结果\n",
    "print(add(2.7, 4.5)) # 输出浮点数相加的结果\n",
    "print(add('abc', 'def')) # 输出字符串拼接的结果\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5fcdf0fc-e705-41b0-8e88-8ffe7ce1ffaa",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'i' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mi\u001b[49m[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m:\u001b[38;5;241m1\u001b[39m:\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n",
      "\u001b[1;31mNameError\u001b[0m: name 'i' is not defined"
     ]
    }
   ],
   "source": [
    "i[-1:1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8b80e384-ba71-464d-a4af-29f71dd80380",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'nmlkgihgfedc'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i[-1:1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51a1d6dc-9a26-49b3-93ff-1d6cde3bd9c5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "24443a75-3730-4814-9614-3ec284b323c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "i='abcdefghigklmn'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e278f6f-f51d-4e24-836d-f2321cbc0521",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38ffe4a8-ade1-423e-b38e-5e33891ca301",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2cf903a-d283-4631-a0fa-818915275622",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
